﻿Imports System.Data.SqlClient

Public Class clsDistribucion
 
    Public Function Insertar(ByVal CLAVE As String, ByVal FECHA As Date, ByVal CLAVE_OPERACION As String, ByVal CANTIDAD As Double, ByVal ENTREGO As String)
        Dim sql As String = "Insert Into DISTRIBUCION_OPE " & _
                            "VALUES (" & _
                            "@CLAVE," & _
                            "@FECHA," & _
                            "@IDOPERACION," & _
                            "@OPERACION," & _
                            "@ENTREGADO," & _
                            "@HORA_ENTREGA," & _
                            "@TERMINADO," & _
                            "@HORA_TERMINO," & _
                            "@ENTREGO," & _
                            "@IDUSUARIO," & _
                            "@PENDIENTE," & _
                            "@TOTAL," & _
                            "@IMPRESO)" & _
                            " SELECT SCOPE_IDENTITY()"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CLAVE", CLAVE)
        Command.Parameters.AddWithValue("FECHA", FECHA)
        Command.Parameters.AddWithValue("IDOPERACION", BuscarIntDatoCitra("SELECT IDOPERACION FROM OPERACIONES WHERE CLAVE='" & CLAVE_OPERACION & "'"))
        Command.Parameters.AddWithValue("OPERACION", CLAVE_OPERACION)
        Command.Parameters.AddWithValue("ENTREGADO", CANTIDAD)
        Command.Parameters.AddWithValue("HORA_ENTREGA", Now())
        Command.Parameters.AddWithValue("TERMINADO", 0)
        Command.Parameters.AddWithValue("HORA_TERMINO", Now())
        Command.Parameters.AddWithValue("ENTREGO", ENTREGO)
        Command.Parameters.AddWithValue("IDUSUARIO", BuscarIntDatoInicial("SELECT IDUSUARIO FROM USUARIOS_CITRA WHERE NOMBRE_USUARIO='" & UsuarioActivo & "'"))
        Command.Parameters.AddWithValue("PENDIENTE", 1)
        Command.Parameters.AddWithValue("TOTAL", 0)
        Command.Parameters.AddWithValue("IMPRESO", 0)

        cnConn.Open()

        Try
            Insertar = Convert.ToInt32(Command.ExecuteScalar)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try


    End Function
    Public Sub InsertarCapacidad(ByVal FECHA As Date, ByVal CLAVE As String, ByVal CAPACIODAD As Double)
        Dim sql As String = "Insert Into CAPACIDAD " & _
                            "VALUES (" & _
                            "@FECHA," & _
                            "@CLAVE," & _
                            "@CAPACIDAD)"


        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("CLAVE", CLAVE)
        Command.Parameters.AddWithValue("FECHA", FECHA)
        Command.Parameters.AddWithValue("CAPACIDAD", 0)


        cnConn.Open()

        Try
            Convert.ToInt32(Command.ExecuteScalar)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Information, "Aviso")
        End Try
    End Sub
    Sub ActualizaCapacidad(ByVal FECHA As Date, ByVal CLAVE As String, ByVal CAPACIODAD As Double)
        Dim FECHA_ACTUAL As String = FECHA.ToString("MM/dd/yyyy")
        Call SetSqlCitra("UPDATE CAPACIDAD SET CAPACIDAD=" & CAPACIODAD & " WHERE CLAVE='" & CLAVE & "' AND FECHA='" & FECHA_ACTUAL & "'")
    End Sub
End Class
